package com.zg.common.core;

import java.util.Collection;
import java.util.Map;

import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil;
import com.zg.common.core.exception.E;

import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.IdcardUtil;

/**
 * 断言，用于参数校验
 * @author Zxb
 */
@SuppressWarnings({"AlibabaClassNamingShouldBeCamel", "unused"})
public class A {
    public static void isNotNull(Object obj, String suffix) {
        if (obj == null) {
            E.VALID_NOT_NULL.happen(suffix);
        }
    }

    public static void isNotEmpty(Collection<?> c, String suffix) {
        if (c == null || c.isEmpty()) {
            E.VALID_NOT_EMPTY.happen(suffix);
        }
    }

    public static void isNotEmpty(Map<?, ?> map, String suffix) {
        if (map == null || map.isEmpty()) {
            E.VALID_NOT_EMPTY.happen(suffix);
        }
    }

    public static void isNotBlank(String str, String suffix) {
        if (StrUtil.isBlank(str)) {
            E.VALID_NOT_BLANK.happen(suffix);
        }
    }

    public static void isTrue(Boolean b, String suffix) {
        if (b == null || !b) {
            E.VALID_TRUE.happen(suffix);
        }
    }

    public static void isMatch(String str, String pattern, String suffix) {
        if (pattern == null
                || !ReUtil.isMatch(pattern, str)) {
            E.VALID_MATCH.happen(suffix);
        }
    }

    public static void isInDatabase(Object obj, String suffix) {
        if (obj == null) {
            E.VALID_IN_DATABASE.happen(suffix);
        }
    }

    public static void isMobile(String str, String suffix) {
        if (!Validator.isMobile(str)) {
            E.VALID_MATCH.happen(suffix);
        }
    }

    public static void isMobile(String str) {
        if (!Validator.isMobile(str)) {
            E.VALID_MATCH.happen("手机号");
        }
    }

    public static void isEmail(String str, String suffix) {
        if (!Validator.isEmail(str)) {
            E.VALID_MATCH.happen(suffix);
        }
    }

    public static void isEmail(String str) {
        if (!Validator.isEmail(str)) {
            E.VALID_MATCH.happen("邮箱");
        }
    }

    public static void isIdCard(String str, String suffix) {
        if (!IdcardUtil.isValidCard(str)) {
            E.VALID_MATCH.happen(suffix);
        }
    }

    public static void isIdCard(String str) {
        if (!IdcardUtil.isValidCard(str)) {
            E.VALID_MATCH.happen("身份证");
        }
    }

    public static void isIp(String str, String suffix) {
        if (!Validator.isIpv4(str) && !Validator.isIpv6(str)) {
            E.VALID_MATCH.happen(suffix);
        }
    }
}
